package nero.yncc.com.createart.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.Layout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;

import nero.yncc.com.createart.R;
import nero.yncc.com.createart.bean.BeanCategory;
import nero.yncc.com.createart.bean.BeanTypeIn;
import nero.yncc.com.createart.bean.SearchInBean;

/**
 * Created by nero on 17-6-26.
 */

public class AdapterTypeALlInText extends RecyclerView.Adapter<AdapterTypeALlInText.Holder> {

    Context context;
    ArrayList<BeanCategory> arrayList;
    AdapterSearchAll.DochildrenClick dochildrenClick;

    public AdapterTypeALlInText(Context context, ArrayList<BeanCategory> arrayList, AdapterSearchAll.DochildrenClick dochildrenClick) {
        this.context = context;
        this.arrayList = arrayList;
        this.dochildrenClick = dochildrenClick;
    }



    @Override
    public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
//        View view = LinearLayout.inflate(context, R.layout.single_textview_type, null);
        View view = LayoutInflater.from(context).inflate( R.layout.single_textview_type, null);
        view.setLayoutParams(new LinearLayout.LayoutParams(-1,-2));
        Holder hOlder = new Holder(view);
        return hOlder;
    }

    @Override
    public void onBindViewHolder(Holder holder, final int position) {
        BeanCategory bean=arrayList.get(position);


        holder.tv_content.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dochildrenClick.click(position);
                Onchoose(position);
                notifyDataSetChanged();
            }
        });

        if(bean.isChoose()){
            holder.tv_content.setText("√ "+bean.getName());
            holder.tv_content.setTextColor(context.getResources().getColor(R.color.project_yellow));
            holder.tv_content.setBackgroundResource(R.drawable.border_yellow);
        }else{
            holder.tv_content.setText("  "+bean.getName()+" ");
            holder.tv_content.setTextColor(context.getResources().getColor(R.color.textColorGray_deep));
            holder.tv_content.setBackgroundResource(R.color.lineColorGray2);
        }
    }

    private void Onchoose(int position){
        for (BeanCategory bean:arrayList){
            bean.setChoose(false);
        }
        arrayList.get(position).setChoose(true);
    }

    @Override
    public int getItemCount() {
        return arrayList.size();
    }

    class Holder extends RecyclerView.ViewHolder {
        TextView tv_content;

        public Holder(View itemView) {
            super(itemView);
            tv_content=itemView.findViewById(R.id.tv_content);
        }
    }
}
